package main

import (
	"fmt"
	"runtime"
	"time"
)

func main() {
	ch := make(chan int)
	quit := make(chan bool)
	go func() {
		for i := 0; i < 5; i++ {
			ch <- i
			time.Sleep(time.Second)
		}
		close(ch)
		quit <- true
		runtime.Goexit()
	}()

	for {
		select {
		case num := <-ch:
			fmt.Println("读到：", num) // 模拟使用数据
		case <-quit:
			//break
			//runtime.Goexit()
			return
		}
		fmt.Println("============") // select 自身不带有循环机制，需借助外层 for 来循环监听
	}
}
